package cn.hbcj.servlet.dao.Impl;

import cn.hbcj.servlet.dao.UserDao;
import cn.hbcj.servlet.domain.User;
import cn.hbcj.servlet.utils.DBUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

public class UserDaoImpl  implements UserDao{
    private QueryRunner runner=new QueryRunner();

    @Override
    public void save(User u) throws SQLException {

    }

    @Override
    public void delete(int id) throws SQLException {

    }

    @Override
    public void update(User u) throws SQLException {

    }

    @Override
    public User findByid(int id) throws SQLException {
        String sql="select * from user where id=? ";
        User user=runner.query(DBUtils.getConnection(),sql,
                new BeanHandler<User>(User.class),id);
        return user;
    }

    @Override
    public List<User> findAll() throws SQLException {
        String sql="select * from user";
        List<User> users= runner.query(DBUtils.getConnection(),sql,new BeanListHandler<User>(User.class));
        return users;
    }


}
